/*
 * server-side-provider
 * Copyright (C) Ivan Surzhenko 2009 <i.surzhenko@gmail.com>
 * 
 * server-side-provider is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * server-side-provider is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
#ifndef PROCESSOR_H_
#define PROCESSOR_H_

#include <stdlib.h>

#include "log.h"

#include <pthread.h>

enum RunMode
{
	rm_Thread,
	rm_Process
};

class Processor
{
	public:
		Processor(RunMode mode = rm_Thread);
		~Processor();
	
		bool Run();
		void Stop();
		
		RunMode GetMode();
		
	protected:
		virtual void Process() = 0;
		
		virtual void OnRun() = 0;
		virtual void OnAfterRun() = 0;
		virtual void OnStop() = 0;
		virtual void OnAfterStop() = 0;
		
	private:
		RunMode m_mode;
		pthread_t th;
		
		bool m_stoping;
		
		static void Work(Processor * object);
};

#endif /*PROCESSOR_H_*/
